<%--
  Created by IntelliJ IDEA.
  User: 武露斌
  Date: 2021/10/22
  Time: 19:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-1.8.2.min.js"></script>
    <script src="../../js/fileupload.js"></script>
    <link rel="stylesheet" href="../../css/css.css">
    <link rel="stylesheet" href="../../css/img.css">
</head>
<body>

<form>
    ID:<input type="text" name="eid" value="${param.eid}"><br>
    文章标题:<input type="text" name="title"><br><br>
    文章图片:
    <div class="photoUpLoad" >
        <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
        <img src="" alt="" class="photoEcho">
    </div><br><br>
    文章内容:<input type="text" name="content"><br>
    标签名称:
    <select name="tid">
        <option value="">请选择标签</option>
    </select>


</form>
<input type="button" value="编辑" onclick="upda()">

</body>
</html>
<script>

    $.ajaxSettings.async=false

    $.ajax({
        url:"listtag.do",
        type:"post",
        dataType:"json",
        success:function (data) {
            for (var i = 0; i <data.length ; i++) {
                $("[name='tid']").append('<option value="'+data[i].tid+'">'+data[i].tname+'</option>')
            }
        }
    })


    $.ajax({
        url:"hui.do",
        data: {"eid":${param.eid}},
        type:"post",
        dataType:"json",
        success:function (data) {
            console.log(data)
            $("[name='title']").val(data.title)
            $(".photoEcho").prop("src",data.img)
            $("[name='content']").val(data.content)
            $("[name='tid']").val(data.tid)


        }
    })




    function upda() {
        var formData = new FormData($("form")[0]);
        $.ajax({
            url:"upda.do",
            data:formData,
            type: "post",
            dataType: "json",
            success:function (data) {
                if (data>0){
                    alert("编辑成功")
                    location="list.do"
                }else{
                    alert("编辑失败")
                }
            },processData:false,contentType:false
        })
    }

</script>


























